
#include "epollLoop.hpp"

class Server
{
public:
    void init(int port = 10)
    {
        for (int i = 0; i < port; i++)
        {
            int socketfd = createSocket(m_port + i);
            m_epollLoop.addConnect(socketfd, EPOLLIN);
        }
    }

    void runServer()
    {
        m_epollLoop.run();
    }

private:
    int createSocket(int port)
    {
        int fd = socket(AF_INET, SOCK_STREAM, 0);
        sockaddr_in addr;
        addr.sin_family = AF_INET;
        addr.sin_addr.s_addr = htonl(INADDR_ANY);
        addr.sin_port = htons(port);
        if (bind(fd, (sockaddr *)&addr, sizeof(addr)))
        {
            close(fd);
            printf("bind filed!!!");
            return -1;
        }
        listen(fd, 10);
        return fd;
    }
    EpollLoop m_epollLoop;
    int m_port = 9999;
};

int main()
{
    Server serv;
    serv.init();
    serv.runServer();
    return 0;
}